;
; ------------------------------------------------------------
;
;   PureBasic - Sprite example file
;
;    (c) 2001 - Fantaisie Software
;
; ------------------------------------------------------------
;

If InitSprite() = 0 Or InitKeyboard() = 0
  MessageRequester("Error", "Can't open DirectX 7 or later", 0)
  End
EndIf

;
; Now, open a 640*480 - 16 bits (65000 colours) screen
;

If OpenScreen(640, 480, 16, "Sprite")

  ; Load our 16 bit sprite (which is a 24 bit picture in fact, as BMP doesn't support 16 bit format)
  ; 
  LoadSprite(0, "Data\PureBasic.bmp", 0)
  CopySprite(0,1,0)
  
  ; Draw some red line on our sprite
  ;
  If StartDrawing(SpriteOutput(1))
    FrontColor(RGB(255, 0, 0))
    For k = 0 To SpriteHeight(1) Step 2
      Line(0, k, SpriteWidth(1), 0)
    Next
    StopDrawing()
  EndIf

  Repeat
    
    ; Inverse the buffers (the back become the front (visible)... And we can do the rendering on the back)
    
    FlipBuffers()
    
    ClearScreen(RGB(0,0,0))
    
    ; Draw our sprite

    ClipSprite(0, 0, 0, x, x/8)
     
    DisplaySprite(0, x, 100)
    DisplaySprite(1, x, x)
    DisplaySprite(0, 600-x, x)
    x+1
    
    ExamineKeyboard()
  Until x > 500 Or KeyboardPushed(#PB_Key_Escape)
  
Else
  MessageRequester("Error", "Can't open a 640*480 - 16 bit screen !", 0)
EndIf

End   